package com.ruoyi.web.controller.translation;

import java.util.Arrays;
import java.util.List;

/**
 * @Title:
 * @author: WYJ
 * @date: 2025/10/10
 */
public class BaiduTranslationExample {

    public static void main1(String[] args) {
        // 方式1: 基础使用
        BaiduTranslator translator = new BaiduTranslator();

        try {
            // 显示支持的语言
            System.out.println("=== 支持的语言 ===");
            translator.getSupportedLanguages().forEach((name, code) -> {
                System.out.printf("%s: %s\n", name, code);
            });

            // 单条翻译
            System.out.println("\n=== 单条翻译 ===");
            String text = "The loser who was humiliated by the public is actually a full-level boss who has hidden everything! With one strike, the entire cultivation world was slapped in the face!";
            //高棉语 hkm 菲律宾语 fil 泰米尔语 tam 缅甸语 bur 印地语 hi
            String result = translator.translateTwo(text, "en","hi");
            System.out.println("原文: " + text);
            System.out.println("译文: " + result);


            // 翻译到不同语言
            System.out.println("\n=== 多语言翻译 ===");
            String[] languages = {"en", "jp", "kor", "fra", "spa"};
            String[] languageNames = {"英语", "日语", "韩语", "法语", "西班牙语"};

            for (int i = 0; i < languages.length; i++) {
                String translated = translator.translate(text, languages[i]);
                System.out.printf("%s: %s\n", languageNames[i], translated);
            }

            // 批量翻译
            System.out.println("\n=== 批量翻译 ===");
            List<String> texts = Arrays.asList(
                    "早上好",
                    "谢谢你的帮助",
                    "这个产品很好用",
                    "我学习编程"
            );

            List<String> batchResults = translator.translateBatch(texts, "en");
            for (int i = 0; i < texts.size(); i++) {
                System.out.printf("%s -> %s\n", texts.get(i), batchResults.get(i));
            }

        } finally {
            translator.close();
        }

        // 方式2: 带速率限制的使用
        System.out.println("\n=== 带速率限制的翻译 ===");
        BaiduTranslatorWithRateLimit rateLimitedTranslator = new BaiduTranslatorWithRateLimit();

        String[] testTexts = {
                "人工智能",
                "机器学习",
                "深度学习",
                "自然语言处理"
        };

        for (String testText : testTexts) {
            String translated = rateLimitedTranslator.translateWithRetry(testText, "en");
            System.out.printf("%s -> %s\n", testText, translated);
        }
    }



    public static void main(String[] args) {
        // 方式1: 基础使用
        BaiduTranslator translator = new BaiduTranslator();

        try {
            // 显示支持的语言
            System.out.println("=== 支持的语言 ===");
            translator.getSupportedLanguages().forEach((name, code) -> {
                System.out.printf("%s: %s\n", name, code);
            });

            // 单条翻译
            System.out.println("\n=== 单条翻译 ===");
            String text = "今天天气";
            //高棉语 hkm 菲律宾语 fil 泰米尔语 tam 缅甸语 bur 印地语 hi

            String result = translator.translateTwo(text, "zh","kh");
            System.out.println(" 高棉语译文: " + result);

            System.out.println(" 缅甸语: " +translator.translateTwo(text, "zh","bur"));
            System.out.println(" 泰米尔语: " +translator.translateTwo(text, "zh","tam"));
/*            String text = "The loser who was humiliated by the public is actually a full-level boss who has hidden everything! With one strike, the entire cultivation world was slapped in the face!";
            //高棉语 hkm 菲律宾语 fil 泰米尔语 tam 缅甸语 bur 印地语 hi

            String result = translator.translateTwo(text, "en","hkm");
            System.out.println(" 高棉语译文: " + result);
            String result1 = translator.translateTwo(text, "en","fil");
            System.out.println(" 菲律宾语 译文: " + result1);
            String result2 = translator.translateTwo(text, "en","tam");
            System.out.println(" 泰米尔语 译文: " + result2);
            String result3 = translator.translateTwo(text, "en","bur");
            System.out.println(" 缅甸语 译文: " + result3);
            String result4 = translator.translateTwo(text, "en","hi");
            System.out.println(" 印地语 译文: " + result4);*/
            // 翻译到不同语言
            System.out.println("\n=== 多语言翻译 ===");






        } finally {
            translator.close();
        }


    }
}

